﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.AspNetCore.Mvc.Filters;
using WomanMotion.WebApi.Service.IService;

namespace WomanMotion.WebApi.Api.Filters
{
    /// <summary>
    /// 权限控制 放弃这里在权限过滤器处理
    /// </summary>
    public class AccessControlAttribute : Attribute, IActionFilter
    {
        //private readonly ICommonService _common;

        ///// <summary>
        ///// 过滤器构造函数
        ///// </summary>
        ///// <param name="common"></param>
        //public AccessControlAttribute(ICommonService common)
        //{
        //    _common = common;
        //}

        /// <summary>
        /// Action执行后
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnActionExecuted(ActionExecutedContext context)
        {
        }

        /// <summary>
        /// Action执行前
        /// </summary>
        /// <param name="context"></param>
        /// <exception cref="NotImplementedException"></exception>
        public void OnActionExecuting(ActionExecutingContext context)
        {
            //这里进行权限控制
            //当控制器标注特效[AllowAnonymous] 则不需要进行权限控制
            //var isall = context.ActionDescriptor.EndpointMetadata.OfType<AllowAnonymousAttribute>().Any();//IAllowAnonymous
            //var i = 0;
        }
    }
}